<?
	include("includes/config.php");
	include("includes/login.php");
	include("includes/functions.php");
	$nr_comanda = $_GET['nr_comanda'];
	$nr_inmatc = $_GET['nr_inmat'];
	$id_comanda = $_GET['id_comanda'];
	if(@$_POST['adauga']){
		$simptome = $_POST['simptome'];
		$constatari = $_POST['constatari'];
		$nr_inmatculare = $_POST['inmatric'];
		mysql_query("insert into comenzi_simptome_constatari (id_constatare,id_comanda,simptome,constatari,numar_inmatriculare) values(NULL,'$id_comanda','$simptome','$constatari','$nr_inmatculare') ") or die(mysql_error());
	}
	if(@$_GET['sterge']){
		$id_const = $_GET['sterge'];
		mysql_query("delete from comenzi_simptome_constatari where id_constatare = '$id_const' ");
	}
?>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="header"><h1> <? echo detaliFirma('nume_firma'); ?></h1></div>
		<div id="warper">
			<?
				$resMeniu = mysql_query("select * from meniu");
			?>
			<div id="menu">
				<ul>
					<? while($rowMen = mysql_fetch_array($resMeniu)): ?>
					<li><a href="<?echo $rowMen['link'];?>"><? echo $rowMen['numeLink']; ?></a></li>
					<? endwhile; ?>
				</ul>
			</div>
			<div id="content">
				<div id="contentWrap">
					<div class="block" style="height:60px;">
						<div style="width:380px; float:left;height:60px;">
							<div style="width:380px;height:40px;" >
								<b style="color:#00a652;font-size:18px;">Comanda Deschisa Nr. <? echo $nr_comanda; ?></b>
							</div>
								<div style="width:385px;float:left">
								<a class="buton" href="/comandanoua.php?nr_comanda=<? echo $nr_comanda; ?>&id_client=1&id_masina=1" >Sumar </a>&nbsp;
								<a class="buton" href="/comandanoua_simptome_constatari.php?id_comanda=<? echo $id_comanda; ?>&nr_comanda=<? echo $nr_comanda; ?>&id_client=1&id_masina=1&nr_inmat=<? echo @$_GET['nr_inmat']; ?>" >Simptome / Constatari </a>&nbsp;
								<a class="buton" href="/comandanoua_materiale.php?id_comanda=<? echo $id_comanda; ?>&nr_comanda=<? echo $nr_comanda; ?>&id_client=1&id_masina=1&nr_inmat=<? echo @$_GET['nr_inmat']; ?>" >Materiale </a>&nbsp;
								<a class="buton"  href="/comandanoua_reparatii.php?id_comanda=<? echo $id_comanda; ?>&nr_comanda=<? echo $nr_comanda; ?>&id_client=1&id_masina=1&nr_inmat=<? echo @$_GET['nr_inmat']; ?>"  >Reparatii </a>&nbsp;
							</div>
						</div>
						<div style="width:200px;height:55px;background:#707070;float:left;margin-left:180px;padding:4px;">
							<?
								/**************************** MATERIALE QUERY **************************/
									$res_pret_materiale = mysql_query("select pret,cant from comenzi_materiale,comenzi_materiale_relatii where comenzi_materiale.id_material = comenzi_materiale_relatii.id_material and id_comanda = '$id_comanda' ");
									$pret_materiale = array();
									while($rowPret = mysql_fetch_array($res_pret_materiale)){
										$pret_materiale[] = $rowPret['pret'] * $rowPret['cant']  ;
									}
									$pret_materiale = array_sum($pret_materiale);
								/**************************** MATERIALE QUERY **************************/	
									
								/**************************** REPARATI QUERY **************************/
									$res_pret_reparatii = mysql_query("select tarif,cant from comenzi_reparatii where  id_comanda = '$id_comanda' ");
									$pret_reparatii = array();
									while($rowPret = mysql_fetch_array($res_pret_reparatii)){
										$pret_reparatii[] = $rowPret['tarif'] * $rowPret['cant']  ;
									}
									$pret_reparatii = array_sum($pret_reparatii);
								/**************************** REPARATI QUERY **************************/
							?>
							Total materiale cu TVA: <? echo $pret_materiale; ?> RON<br/>
							
							Total Reparatii cu TVA <? echo $pret_reparatii; ?> RON<br/>
							<hr>
							<b>Total <? echo $pret_materiale + $pret_reparatii  ?> RON</b>
						</div>
					</div>
					<h2>Simptome</h2>
					<table class="block">
						<tr id="capTabel">
							<td style="width:100px;">Masina</td>
							<td style="width:330px;">Simptome </td>
							<td style="width:330px;">Constatari</td>
							<td style="width:100px;">Edit</td>
						<tr>
							<?
								$resS = mysql_query("select * from comenzi_simptome_constatari where id_comanda = '$id_comanda' ");
								while($rowS = mysql_fetch_array($resS)):
							?>
						<tr style="height:30px;">
							<td style="width:100px;"><? echo $rowS['numar_inmatriculare']; ?></td>
							<td style="width:330px;"><? echo $rowS['simptome']; ?></td>
							<td style="width:330px;"><? echo $rowS['constatari']; ?></td>
							<td style="width:100px;text-align:center;"><a href="/comandanoua_simptome_constatari.php?id_comanda=<? echo $_GET['id_comanda']; ?>&nr_comanda=<? echo $_GET['nr_comanda']; ?>&id_client=<? echo $_GET['id_client']; ?>&id_masina=<? echo $_GET['id_masina']; ?>&nr_inmat=<? echo $_GET['nr_inmat']; ?>&sterge=<?  echo $rowS['id_constatare']; ?>" class="buton">Sterge</a></td>
						</tr>
							<? endwhile; ?>
					</table>
					
					<div class="block">
					<form action="" method="post">
						<input type="hidden" name="inmatric" value="<? echo $_GET['nr_inmat'];?>">
						<p>
							<label>Simptome</label>
							<textarea class="text" name="simptome"></textarea>
						</p>
						<p>
							<label>Constatari</label>
							<textarea class="text" name="constatari"></textarea>
						</p>
						<input class="buton" type="submit" value="Adauga" name="adauga" />
					</form>
					</div>
			
					
				</div>
			</div>
		</div>
	</body>
</html>